package cn.threewaters.qtyy.web.facade;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.google.common.collect.Maps;

import cn.threewaters.qtyy.dit.one.entity.SysFunction;

public class MenuTree {
	public static Map<String, Object> mapArray = new LinkedHashMap<String, Object>();
	public List<SysFunction> menuCommon;
	public List<Object> list = new ArrayList<Object>();

	public List<Object> menuList(List<SysFunction> sysFunctions) {
		this.menuCommon = sysFunctions;
		for (SysFunction sysFunction : sysFunctions) {
			Map<String, Object> mapArr = Maps.newLinkedHashMap();
			if (sysFunction.getParentId().equals("0")) {
				mapArr.put("id", sysFunction.getId());
				mapArr.put("name", sysFunction.getFunName());
				mapArr.put("pid", sysFunction.getParentId());
				mapArr.put("url", sysFunction.getFunUrl());
				mapArr.put("children", menuChild(sysFunction.getId()));
				list.add(mapArr);
			}
		}
		return list;
	}

	public List<?> menuChild(String id) {
		List<Object> lists = new ArrayList<Object>();
		for (SysFunction sysFunction : menuCommon) {
			Map<String, Object> childArray = new LinkedHashMap<String, Object>();
			if (sysFunction.getParentId().equals(id)) {
				childArray.put("id", sysFunction.getId());
				childArray.put("name", sysFunction.getFunName());
				childArray.put("pid", sysFunction.getParentId());
				childArray.put("url", sysFunction.getFunUrl());
				childArray.put("children", menuChild(sysFunction.getId()));
				lists.add(childArray);
			}
		}
		return lists;

	}
}
